<template>
  <div class="Invi"
       @click="goInvi(main._id)">
    <User :user="main.username"
          :time="main.time"></User>
    <h1 class="title">
      {{ main.title }}
    </h1>
    <div class="main">
      {{ main.main }}
    </div>
    <div class="foot">
      <div class="star">
        <van-icon name="like-o"
                  v-if="isStar" />
        <van-icon name="like"
                  v-else />
        <span>{{ main.stars }}</span>
      </div>
      <div class="comment">
        <van-icon name="comment-o" />
        <span>{{ comment(main.comments.length)}}</span>
      </div>
    </div>
  </div>
</template>
<script>
import User from './User.vue'
export default {
  components: { User },
  props: {
    main: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  methods: {
    goInvi (id) {
      this.$router.push(`/Invi/${id}`)
    }
  },
  computed: {
    isStar () {
      return this.$store.state.User.LoginStatus ? this.$store.state.User.user.stars.findIndex(item => item === this.main._id) === -1 : false
    },
    comment () {
      return num => {
        if (num >= 99) {
          return '99+'
        } else {
          return num
        }
      }
    }
  }
}
</script>
<style lang="less" scoped>
.Invi {
  background-color: #fff;
  padding: 10px;
  border-radius: 7%;
  display: flex;
  flex-direction: column;

  .title {
    color: #141414;
    font-weight: 700;
    font-size: 16px;
  }
  .main {
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    word-break: break-all;
  }
  .foot {
    margin-top: 10px;
    font-size: 16px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: relative;
    .star {
      margin-right: 10px;
    }
  }
}
</style>
